@extends('backstage.layout.master')
@section('title', '优惠劵列表')
@section('content')
    <style>
        .state li {
            list-style: none;
            float: left;
            padding: 0 20px;
            text-align: center;
            height: 40px;
            line-height: 40px;
        }

        .state ul {
            margin: 0;
        }

        .state a {
            font-size: 12px;
        }
        .che a {
            font-weight: bold;
            color: #7c7c7c;
        }
    </style>
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a href="backstage/home">主页</a>
            </li>

            <li class="active">
                <a href="/backstage/coupons/addcoupons">添加优惠劵</a>
            </li>
            <li>
                优惠劵列表
            </li>
        </ul><!-- .breadcrumb -->

    </div>

    <div class="page-content">
        <div class="page-header">
            <h1>
                优惠劵
                <small>
                    <i class="icon-double-angle-right"></i>
                    优惠劵列表
                </small>
                <span class="pull-right">
                    <button class="btn btn-primary" onclick="javascript:window.location.href='{{asset('')}}backstage/coupons/addcoupons';">添加优惠劵</button>
                </span>
            </h1>
        </div>
        <div class="row">
            <div class="col-xs-12">
                <small>
                    <i class="icon-double-angle-right"></i>
                    提示：1.点击渠道编号查看优惠券列表
                </small>
                <!-- PAGE CONTENT BEGINS -->
                <div class="table-responsive">
                    <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <!-- <th >编号</th> -->
                            <th>渠道编号</th>
                            <th>券名</th>
                            <th>金额</th>
                            <th>数量</th>
                            <th>已领取</th>
                            <th>已使用</th>
                            <th>优惠类型</th>
                            <th>绑定类型</th>
                            <th>创建时间</th>
                            <th>开始时间</th>
                            <th>结束时间</th>
                            <th width="150px">操作区</th>
                        </tr>
                        </thead>

                        <tbody>
                        @foreach ($channels as $channel)
                        <tr class="" data-tr-id="{{isset($channel->channel_id)?$channel->channel_id:''}}">
                            <!-- <td>
                                {{isset($channel->id)?$channel->id:''}}
                            </td> -->
                            <td>
                                <a target="_blank" href="backstage/coupons/coupon-list-channel?channel_id={{isset($channel->channel_id)?$channel->channel_id:''}}">{{isset($channel->channel_id)?$channel->channel_id:''}}</a>
                            </td>
                            <td>
                                {{isset($channel->name)?$channel->name:''}}
                            </td>
                            <td>
                                {{isset($channel->price)?$channel->price:''}}
                            </td>
                            <td>
                                {{isset($channel->num)?$channel->num:''}}
                            </td>
                            <td>{{isset($channel->send)?$channel->send:''}}</td>
                            <td>{{isset($channel->use)?$channel->use:''}}</td>
                            <td>
                                @if(isset($channel->coupon_type) && $channel->coupon_type == 1)
                                优惠券(满减)
                                @elseif(isset($channel->coupon_type) && $channel->coupon_type == 2)
                                现金券
                                @else
                                未知
                                @endif
                            </td>
                            <td>
                                @if(isset($channel->binding_type)&&($channel->binding_type==2))
                                    礼包券
                                @else
                                    单券
                                @endif
                            </td>
                            <td>
                                {{isset($channel->created_at)?date('Y-m-d H:i',$channel->created_at):""}}
                            </td>
                            <td>
                                {{isset($channel->begin_time)?date('Y-m-d H:i',$channel->begin_time):''}}
                            </td>
                            <td>
                                {{isset($channel->end_time)?date('Y-m-d H:i',$channel->end_time):''}}
                            </td>
                            <td class="center" style="padding-top: 15px">
                                <div class="visible-md visible-lg hidden-sm hidden-xs action-buttons">
                                    <input class="channel_id" type="test" value="{{ isset($channel->id)?$channel->id:''}}"
                                           style="display: none;">
                                    <a class="issuing"
                                       onclick="javascript:window.location.href='{{asset('')}}backstage/coupons/issuing?id={{ isset($channel->id)?$channel->id:''}}';"
                                       title="发放优惠券" style="color:#d77600;cursor: pointer;">
                                        <i class="icon-download-alt bigger-130"></i>
                                    </a>
                                    <a class="detail"
                                       onclick="javascript:window.location.href='{{asset('')}}backstage/coupons/detail?id={{ isset($channel->id)?$channel->id:''}}';"
                                       title="详情" style="color:#0914d7;cursor: pointer;">
                                        <i class="icon-edit bigger-130"></i>
                                    </a>
                                    <a class="deletechannel" title="删除" style="color:#d7030b;cursor: pointer;"
                                        onclick="delete_btn('{{isset($channel->channel_id)?$channel->channel_id:''}}')">
                                        <i class="icon-trash bigger-130"></i>
                                    </a>
                                    @if(isset($channel->binding_type)&&($channel->binding_type==2))
                                    <a class="detail"
                                       onclick="javascript:window.location.href='{{asset('')}}backstage/coupons/binding-coupons?id={{ isset($channel->channel_id)?$channel->channel_id:''}}';"
                                       title="优惠券绑定" style="color:#2e00d7;cursor: pointer;">
                                        <i class="icon-zoom-in bigger-130"></i>
                                    </a>
                                    @else
                                        <a class="detail"
                                           onclick="javascript:window.location.href='{{asset('')}}backstage/coupons/channel-use-range?id={{ isset($channel->id)?$channel->id:''}}';"
                                           title="优惠范围" style="color:#2e00d7;cursor: pointer;">
                                            <i class="icon-zoom-in bigger-130"></i>
                                        </a>
                                    @endif
                                </div>
                            </td>
                        </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>
                <div class="row">
                    <div class="col-sm-6">
                        <div class="dataTables_info" id="sample-table-2_info"></div>
                    </div>
                    <div class="col-sm-6">
                        <div class="dataTables_paginate paging_bootstrap">
                            <?php echo $channels->render(); ?>
                        </div>
                    </div>
                </div>
                <!-- PAGE CONTENT ENDS -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.page-content -->
@stop
@section('script')
    <script type="text/javascript">
        function delete_btn(channel_id){
            swal({
                title: "确定删除？",
                text: "",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                closeOnConfirm: true,
                closeOnCancel: true
            },function (){
            $.ajax({
                    type: "post",
                    url: "/backstage/coupons/delete",
                    data:{"channel_id":channel_id},
                    dataType: 'json',
                    success: function(res){
                        if(res.state==1){
                            swal({
                                title: res.message,
                                text: "",
                                type: "success",
                                timer:2000
                            });
                            $('[data-tr-id='+channel_id+']').remove();
                        }else{
                            swal({
                                title: res.message,
                                text: "",
                                type: "error",
                                timer:3000
                            });
                        }
                    },
                    error:function(){
                     swal({
                            title: "系统繁忙！",
                            text: "",
                            type: "error",
                            timer:2000
                        });
                    }
                });//ajax
            });
        }
        function getQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]); return null;
        }
    </script>
@stop
